//首页网格卡片模型
import 'package:flutter_trip/model/common_model.dart';

class GridNavModel {
  final GridNavItem hotel;
  final GridNavItem flight;
  final GridNavItem travel;

  GridNavModel(
      {required this.hotel, required this.flight, required this.travel});

  // 修改返回类型为 GridNavModel?
  factory GridNavModel.fromJson(Map<String, dynamic> json) {
    // if (json == null) {
    //   return null; // 允许返回 null
    // }
    return GridNavModel(
      hotel: GridNavItem.fromJson(json['hotel']),
      flight: GridNavItem.fromJson(json['flight']),
      travel: GridNavItem.fromJson(json['travel']),
    );
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    if (this.hotel != null) {
      data['hotel'] = this.hotel;
    }
    if (this.flight != null) {
      data['flight'] = this.flight;
    }
    if (this.travel != null) {
      data['travel'] = this.travel;
    }
    return data;
  }
}

class GridNavItem {
  final String startColor;
  final String endColor;
  final CommonModel mainItem;
  final CommonModel item1;
  final CommonModel item2;
  final CommonModel item3;
  final CommonModel item4;

  GridNavItem(
      {required this.startColor,
      required this.endColor,
      required this.mainItem,
      required this.item1,
      required this.item2,
      required this.item3,
      required this.item4});

  factory GridNavItem.fromJson(Map<String, dynamic> json) {
    return GridNavItem(
      startColor: json['startColor'] ?? '',
      // 默认空字符串
      endColor: json['endColor'] ?? '',
      // 默认空字符串
      mainItem: CommonModel.fromJson(json['mainItem']),
      item1: CommonModel.fromJson(json['item1']),
      item2: CommonModel.fromJson(json['item2']),
      item3: CommonModel.fromJson(json['item3']),
      item4: CommonModel.fromJson(json['item4']),
    );
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['startColor'] = this.startColor;
    data['endColor'] = this.endColor;
    if (this.mainItem != null) {
      data['mainItem'] = this.mainItem!.toJson();
    }
    if (this.item1 != null) {
      data['item1'] = this.item1!.toJson();
    }
    if (this.item2 != null) {
      data['item2'] = this.item2!.toJson();
    }
    if (this.item3 != null) {
      data['item3'] = this.item3!.toJson();
    }
    if (this.item4 != null) {
      data['item4'] = this.item4!.toJson();
    }
    return data;
  }
}
